package com.junqi.live.room.application.controller;

import com.junqi.common.entity.AjaxResult;
import com.junqi.live.room.application.convert.LiveRoomDtoConvert;
import com.junqi.live.room.application.convert.LiveTypeDtoConvert;
import com.junqi.live.room.domain.bo.LiveRoomBo;
import com.junqi.live.room.domain.bo.LiveTypeBo;
import com.junqi.live.room.domain.service.LiveRoomDomainService;
import com.junqi.live.room.domain.service.LiveTypeDomainService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/index")
public class LiveIndexController {

    @Resource
    LiveRoomDomainService liveRoomDomainService;
    @Resource
    LiveTypeDomainService liveTypeDomainService;


    /**
     * 首页查询接口
     * @return
     */
    @GetMapping("/")
    public AjaxResult index(){
        Map<String,Object> map=new HashMap<>();
        List<LiveRoomBo> roomList = liveRoomDomainService.listByTypeId("");
        map.put("roomList",roomList.stream().map(m -> LiveRoomDtoConvert.INSTANCE.convertBoToDtO(m)).collect(Collectors.toList()));
        List<LiveTypeBo> typeList = liveTypeDomainService.listAll();
        LiveTypeBo typeBo=new LiveTypeBo();
        typeBo.setId("");
        typeBo.setName("全部分类");
        typeList.add(0,typeBo);
        map.put("typeList",typeList.stream().map(m -> LiveTypeDtoConvert.INSTANCE.convertBoToDtO(m)).collect(Collectors.toList()));
        return AjaxResult.success(map);
    }


    /**
     * 根据分类id查询直播间
     * @return
     */
    @GetMapping("/liveRoomListByTypeId")
    public AjaxResult liveRoomListByTypeId(@RequestParam("typeId") String typeId){
        List<LiveRoomBo> roomList = liveRoomDomainService.listByTypeId(typeId);
        return AjaxResult.success(roomList.stream().map(m -> LiveRoomDtoConvert.INSTANCE.convertBoToDtO(m)).collect(Collectors.toList()));
    }

}
